home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8692 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: gambier.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Fractals
  5. Date: 5 Mar 1996 13:31:12 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hibr0INN7s1@gambier.ugrad.cs.ubc.ca>
  8. References: <4hhv43$49i@sunburst.ccs.yorku.ca>
  9. NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
  10.  
  11. In article <4hhv43$49i@sunburst.ccs.yorku.ca>,
  12. Naftali Sturm <yu114405@yorku.ca> wrote:
  13. >How do you program fractals in C?
  14.  
  15. You define a data type that can hold complex numbers. You can make it an
  16. abstract data type if you wish.
  17.  
  18. Then you define some basic operations: complex multiplication, addition,
  19. norm and so forth.
  20.  
  21. Then you compute the fractal using whatever iterative formula you wish, such as
  22.  
  23.     z = z^2 + C
  24.  
  25. Where z is a complex number (x + iy), C is an arbitrary complex constant. 
  26.  
  27. You look at how fast that grows for various choices of x, which gives you your
  28. fractal 'hills' that you can represent as a colored ``topological map'', where
  29. the color at (x,y) represents the rate of growth of the iterated calculation
  30. for the initial value z = x + iy. Other formulae are possible.
  31.  
  32. For example, if you use Newton's method to find the complex root of three, and
  33. use z as your initial approximation, and then assign one of three colors
  34. to (x,y) based on which of three roots Newton's method converges to with that
  35. starting value, you will end up with a three-colored fractal image.
  36.  
  37.  
  38. One possible representation of a complex number can be:
  39.  
  40. typedef struct {
  41.     double real;
  42.     double imag;
  43. } complex_t;
  44.  
  45. Then you define macros and functions for doing operations on the complex type.
  46. If you go far enough, you may even end up implementing complex transcendental
  47. functions, such as complex sine and cosine.
  48.  
  49. The GNU C compiler has a native complex type, but this is not part of the
  50. standard C language.
  51. -- 
  52.  
  53.